<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="">
    
    <title>首页</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
	<link href="../../css/bootstrap.min.css" rel="stylesheet">
  </head>
  
  <body>
  <script type="text/javascript">
  	$(document).ready(function(){
  		$.post("${pageContext.request.contextPath}/college/findAll",
  		{},
  		function(data, status){
  			for(var i = 0; i < data.data.length; i++)
  			{
  				$("#t").append("<tr>");
  				$("#t").append("<td>"+data.data[i].ename+"</td>"); 
  				$("#t").append("<td><button type='button' class='btn btn-sm'>编辑</button>&emsp;<button type='button' class='btn btn-sm' onclick='loop(value)' value='"+data.data[i].eid+"'>专业</button></td>");
  				$("#t").append("</tr>");
  			}
  		});
  	});
  	
  	function loop(value){
  		window.parent.right.location.href='majorlist.jsp?eid='+value;
  	}
  	
  	function addCollege(){
  		$.ajax({
  			url:"${pageContext.request.contextPath}/college/add",
  			dataType:"json",
  			type:"post",
  			data:{ename:$("#college").val()},
  			success:function(data, status)
  			{
  				if(data.code == 1) {
  					alert(data.message);
  					window.location.href='collegelist.jsp';
  				}else alert(data.message);
  				
  		}});
  	}
  </script>
  
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<h3 class="text-center">
				学院
			</h3>
			<br/>
			<div class="col-md-6 column">
			 <button type="button" class="btn btn-sm" data-toggle="modal" data-target="#myModal">添加</button>
			</div>
			<div class="col-md-6 column">
			</div>
			<br/>
			<table  class="table table-bordered table-hover">
				<thead>
					<tr>
						<th>
							学院
						</th>
						<th>
							菜单
						</th>
					</tr>
				</thead>
				<tbody id="t">
			
				</tbody>
			</table>
		</div>
	</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">
                  	添加学院
                </h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
            </div>
            <form id="form_data">
            <div class="modal-body">
                                                         学院: <input type="text" id="college"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" onclick="addCollege()" class="btn btn-primary">
                   	提交更改
                </button>
            </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
  </body>
</html>
